package com.linkallcloud.core.www;

import java.time.Duration;

import com.linkallcloud.core.util.Utils;

public abstract class TokenBox implements ITokenBox {

    protected LacToken createToken(ISimpleUser su, Duration timeout) {
        if (timeout == null) {
            timeout = Duration.ofMinutes(10);
        }

        LacToken lt = new LacToken(su, Utils.getRandomID(50), timeout);
        String token = lt.toToken();
        if (exist(token)) {
            return createToken(su, timeout);
        } else {
            return lt;
        }
    }

}
